package com.blink.base;

import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.TimeUnit;

/**
 * <Description> </Description>
 * <ClassName> BaseTestSample</ClassName>
 *
 * @Author liuxianzhao
 * @Date 2018年01月12日 15:34
 */
public abstract class BaseTestSample {
    protected Logger logger = LoggerFactory.getLogger(this.getClass().getSimpleName());

    protected static final String ROOT_PATH = "127.0.0.1:2181";


    protected CuratorFramework getZkCurator() {
        RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
        CuratorFramework client =
                CuratorFrameworkFactory.builder()
                        .connectString(ROOT_PATH)
                        .sessionTimeoutMs(5000)
                        .retryPolicy(retryPolicy)
                        .namespace("zk-curator")
                        .build();
        return client;
    }
    protected CuratorFramework getZkCuratorWithoutNamespace() {
        RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
        CuratorFramework client =
                CuratorFrameworkFactory.builder()
                        .connectString(ROOT_PATH)
                        .sessionTimeoutMs(5000)
                        .retryPolicy(retryPolicy)
                        .build();
        return client;
    }

    protected void sleep() {
        try {
            TimeUnit.MINUTES.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    protected void sleep(long seconds) {
        try {
            TimeUnit.SECONDS.sleep(seconds);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}